package com.zlsy.thread.threadpool;

import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

/**
 * @author zhouliang
 * @date 2020/7/4 14:38
 */
public class ShutdownNowThreadPool {
    public static void main(String[] args) throws InterruptedException {
        ExecutorService executorService = Executors.newFixedThreadPool(10);

        for (int i = 0; i < 1000; i++) {
            executorService.execute(() -> {
                try {
                    TimeUnit.MILLISECONDS.sleep(100);
                } catch (InterruptedException e) {
                    System.out.println(Thread.currentThread().getName() + "被中断了");
                }
                System.out.println(Thread.currentThread().getName());
            });
        }
        TimeUnit.SECONDS.sleep(1);

        List<Runnable> runnables = executorService.shutdownNow();
        List<String> list = runnables.stream()
                .map(runnable -> {
                    Class<? extends Runnable> aClass = runnable.getClass();
                    return aClass.getName();
                }).collect(Collectors.toList());
        System.out.println(list);
    }
}
